package com.hc.serviceimpl;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.entity.*;
import com.hc.exception.TlsRuntimeException;
import com.hc.mapper.*;
import com.hc.model.*;
import com.hc.service.*;
import com.hc.util.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

import static com.hc.util.DateUtil.countDate;

/**
 * @author LiuZhiHao
 * @date 2019/8/28 13:48
 * 描述:
 **/
@Service
public class QcEquipmentRecordServiceImpl extends ServiceImpl<QcEquipmentRecordMapper, QcEquipmentRecord> implements QcEquipmentRecordService {

    @Autowired
    private QcEquipmentRecordMapper qcEquipmentRecordMapper;
    @Autowired
    private QcFilestoreService qcFilestoreService;
    @Autowired
    private QcEquipmentMapper qcEquipmentMapper;
    @Autowired
    private UserInfoPost userInfoPost;
    @Autowired
    private QcFilestoreMapper qcFilestoreMapper;
    @Autowired
    private QcMonitorMapper qcMonitorMapper;
    @Autowired
    private IRefrigeratormvService iRefrigeratormvService;
    @Autowired
    private DigitalSignatureMapper digitalSignatureMapper;
    @Autowired
    private IIncubatormvService iIncubatormvService;
    @Autowired
    private IEnvironmentmvService iEnvironmentmvService;
    @Autowired
    private QcDigitalSignatureService qcDigitalSignatureService;
    @Autowired
    private QcEquipmentRecordService qcEquipmentRecordService;
    @Autowired
    private EquipmentRecordServiceImplUtilService equipmentRecordServiceImplUtilService;
    @Autowired
    private IncubSnapshotMapper incubSnapshotMapper;

    private final static String FIXEDTIME = "2024-09-28 00:00:00";

    /**
     * 新增巡检设备记录
     *
     * @param qcEquipmentRecordModel
     */
    @Override
    public void saveQcEquipmentRecord(QcEquipmentRecordModel qcEquipmentRecordModel) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String workStatus = qcEquipmentRecordModel.getWorkStatus();
        int eqId1 = qcEquipmentRecordModel.getEqId();
        Date createTime = new Date();
        String dateStr = sdf.format(createTime);
        if (StringUtils.equals("2", workStatus)) {
            //查询是否有当前设备id对应的当天的上班巡检记录，没有则抛出异常
            List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQcEquipmentRecordModelByIdForOnWork(dateStr, eqId1);
            if (CollectionUtils.isEmpty(list)) {
                throw new TlsRuntimeException("当前设备没有上班巡检记录，无法添加");
            }
        }
        //获取工作台操作模式，1操作前，2操作后
        String workbenchOperationPattern = qcEquipmentRecordModel.getWorkbenchOperationPattern();
        //如果工作台操作模式是操作前
        if (StringUtils.equals(workbenchOperationPattern, "1")) {
            //为qcEquipmentRecordModel对象的工作台操作批次属性赋值
            qcEquipmentRecordModel.setWorkbenchOperationBatch("" + System.currentTimeMillis());
        }
        //设置qcEquipmentRecordModel对象的创建时间为当前时间
        qcEquipmentRecordModel.setCreateTime(new Date());
        //判断当前设备是否是冰箱1和冰箱5，只有这两个冰箱有冷冻温度，其他的冰箱只有冷藏温度
        int eqId = qcEquipmentRecordModel.getEqId();
        QcEquipment qcEquipment = qcEquipmentMapper.selectById(eqId);
        //获取设备名称
        String deviceName = qcEquipment.getDeviceName();
        //如果设置的名称不是1号和5号冰箱，将冷藏温度设置为null
        if (!StringUtils.equalsAnyIgnoreCase(deviceName, "1号冰箱", "海尔医用冷藏冷冻箱5", "5楼-冰箱-2", "6楼-冰箱-1")) {
            qcEquipmentRecordModel.setFreezingTemperature(null);
        }
        //将qcEquipmentRecordModel对象这一条记录添加到qc_equipment_record表中
        qcEquipmentRecordMapper.insert(qcEquipmentRecordModel);
        //获取qcEquipmentRecordModel对象的设备记录id属性值
        Long id = qcEquipmentRecordModel.getId();
        //获取qcEquipmentRecordModel对象的照片路径集合属性值
        List<String> images = qcEquipmentRecordModel.getImages();
        //如果照片路径集合不为空
        if (CollectionUtils.isNotEmpty(images)) {
            //创建一个list集合对象，泛型是QcFilestore对象
            List<QcFilestore> list = new ArrayList<>();
            //遍历获取的images照片路径集合对象
            images.forEach(s -> {
                //创建一个QcFilestore对象
                QcFilestore qcFilestore = new QcFilestore();
                //添加QcFilestore对象的创建人属性
                qcFilestore.setCreateBy(qcEquipmentRecordModel.getCreateBy());
                //添加创建时间为当前时间
                qcFilestore.setCreateTime(new Date());
                //添加文件路径
                qcFilestore.setFileUrl(s);
                //添加设备记录id
                qcFilestore.setRecordId(id);
                //设置设备记录类型为巡检，1为巡检，2为监察
                qcFilestore.setRecordType("1");
                //将被赋值的qcFilestore对象添加到之前创建的list集合中
                list.add(qcFilestore);
            });
            //往qc_filestore表中执行批量添加操作
            qcFilestoreService.saveBatch(list);
        }
    }

    /**
     * 获取巡检完成状态
     *
     * @param qcRecordStatusModel
     * @return
     */
    @Override
    public List<QcRecordStatus> getinspectionStatus(QcRecordStatusModel qcRecordStatusModel) {
        //获取角色类型
        String roleType = qcRecordStatusModel.getRoleType();
        //获取开始时间
        String startTime = qcRecordStatusModel.getStartTime();
        //获取工作状态，是上班还是下班
        String workStatus = qcRecordStatusModel.getWorkStatus();
        //获取设备分类，即巡检的是哪一类设备
        String classifyId = qcRecordStatusModel.getClassifyId();
        //创建一个泛型为QcEquipment（设备对象实体类）对象的list集合对象
        List<QcEquipment> qcEquipments = null;
        //如果设备分类为空
        if (StringUtils.isEmpty(classifyId)) {
            //如果角色类型是5
            if (StringUtils.equals(roleType, "5")) {
                //如果工作类型是上班
                if (StringUtils.equals(workStatus, "1")) {
                    //去qc_equipment表中查询出设备分类为冰箱、液氮罐、气瓶且是否可用为开启且创建时间小于等于开始时间的所有数据
                    List<QcEquipment> qcEquipments1 = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                            .in(QcEquipment::getClassifyId, Arrays.asList("1", "2", "3"))
                            .eq(QcEquipment::getEnable, 0)
                            .le(QcEquipment::getCreateTime, startTime));
                    //将之前查询出来的数据再过滤一下，过滤条件是扫码标识是不等于ZK2211569054977173的数据，然后将过滤出来的数据转换成list集合赋值给上面我们创建的qcEquipments集合对象
                    qcEquipments = qcEquipments1.stream().filter(s -> !StringUtils.equals(s.getScanidentify(), "ZK2211569054977173")).collect(Collectors.toList());
                    //如果工作类型是下班
                } else {
                    //去qc_equipment表中查询出设备分类为液氮罐、气瓶且是否可用为开启且创建时间小于等于开始时间的所有数据
                    qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                            .in(QcEquipment::getClassifyId, Arrays.asList("2", "3"))
                            .eq(QcEquipment::getEnable, 0)
                            .le(QcEquipment::getCreateTime, startTime));
                }
                //筛选液氮罐里面的位置 胚胎库2 胚胎库3
                //新创建一个包含QcEquipment对象的list集合
                List<QcEquipment> qcEquipments1 = new ArrayList<>();
                //遍历qcEquipments集合
                qcEquipments.forEach(s -> {
                    //如果设备分类是液氮罐
                    if (s.getClassifyId().equals("2")) {
                        //如果位置为胚胎库1
                        if (s.getLocation().equals("4")) {
                            //将符合条件的数据放入到新创建的qcEquipments1集合中
                            qcEquipments1.add(s);
                        }
                    }
                });
                //将qcEquipments集合中的所有在qcEquipments1集合中有的数据移除掉
                qcEquipments.removeAll(qcEquipments1);
                //如果角色类型是6
            } else if (StringUtils.equals(roleType, "6")) {
                //如果工作类型是上班
                if (StringUtils.equals(workStatus, "1")) {
                    //去qc_equipment表中查询出设备分类为冰箱、培养箱、操作台、显微镜、培养室、其他仪器设备、离心机且是否可用为开启且创建时间小于等于开始时间的所有数据
                    List<QcEquipment> qcEquipments1 = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                            .in(QcEquipment::getClassifyId, Arrays.asList("1", "4", "5", "6", "7", "8", "11"))
                            .eq(QcEquipment::getEnable, 0)
                            .le(QcEquipment::getCreateTime, startTime));
                    //将之前查询出来的数据再过滤一下，过滤条件是扫码标识是不等于ZK1521568970411545、ZK1511568970369464、ZK1491568970193028、ZK1481568970138180、ZK1531568970442358的数据，
                    // 然后将过滤出来的数据转换成list集合赋值给最初我们创建的qcEquipments集合对象
                    qcEquipments = qcEquipments1.stream().filter(s -> !StringUtils.equalsAny(s.getScanidentify(), "ZK1521568970411545",
                            "ZK1511568970369464", "ZK1491568970193028", "ZK1481568970138180",
                            "ZK1531568970442358")).collect(Collectors.toList());
                    //如果工作类型是下班
                } else {
                    //去qc_equipment表中查询出设备分类为冰箱、液氮罐、培养箱、操作台、显微镜、培养室、其他仪器设备、离心机且是否可用为开启且创建时间小于等于开始时间的所有数据
                    qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                            .in(QcEquipment::getClassifyId, Arrays.asList("1", "2", "4", "5", "6", "7", "8", "11"))
                            .eq(QcEquipment::getEnable, 0)
                            .le(QcEquipment::getCreateTime, startTime));
                }
                //新创建一个包含QcEquipment对象的list集合
                List<QcEquipment> qcEquipments1 = new ArrayList<>();
                //遍历qcEquipments集合
                qcEquipments.forEach(s -> {
                    //如果设备分类为液氮罐
                    if (s.getClassifyId().equals("2")) {
                        //如果位置是胚胎库2或者胚胎库3
                        if (s.getLocation().equals("5") || s.getLocation().equals("6")) {
                            //则将满足条件的QcEquipment对象添加到新创建的qcEquipments1集合中
                            qcEquipments1.add(s);
                        }
                    }
                });
                //将qcEquipments集合中的所有在qcEquipments1集合中有的数据移除掉
                qcEquipments.removeAll(qcEquipments1);
                //如果角色类型为其他的话
            } else {
                //去qc_equipment表中查询出设备分类为1,2,3,4,5,6,7,8,9,10,11且是否可用为开启且创建时间小于等于开始时间的所有数据
                qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                        .in(QcEquipment::getClassifyId, Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"))
                        .eq(QcEquipment::getEnable, 0)
                        .le(QcEquipment::getCreateTime, startTime));
            }
            //如果设备分类不为空
        } else {
            //如果设备分类不是液氮罐
            if (!StringUtils.equals(classifyId, "2")) {
                //去qc_equipment表中查询出设备分类classifyId且是否可用为开启且创建时间小于等于开始时间的所有数据
                List<QcEquipment> qcEquipments1 = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                        .eq(QcEquipment::getClassifyId, classifyId)
                        .eq(QcEquipment::getEnable, 0)
                        .le(QcEquipment::getCreateTime, startTime));
                //如果设备分类为冰箱
                if (StringUtils.equals(classifyId, "1")) {
                    //如果工作状态是上班
                    if (StringUtils.equals(workStatus, "1")) {
                        //如果角色类型是5
                        if (StringUtils.equals(roleType, "5")) {
                            //将之前查询出来的数据再过滤一下，过滤条件是扫码标识是不等于ZK2211569054977173的数据，
                            // 然后将过滤出来的数据转换成list集合赋值给最初我们创建的qcEquipments集合对象
                            qcEquipments = qcEquipments1.stream().filter(s -> !StringUtils.equals(s.getScanidentify(), "ZK2211569054977173")).collect(Collectors.toList());
                            //如果角色类型不是5的话
                        } else {
                            //将之前查询出来的数据再过滤一下，过滤条件是扫码标识是不等于ZK1521568970411545、ZK1511568970369464、ZK1491568970193028、ZK1481568970138180、ZK1531568970442358的数据，
                            // 然后将过滤出来的数据转换成list集合赋值给最初我们创建的qcEquipments集合对象
                            qcEquipments = qcEquipments1.stream().filter(s -> !StringUtils.equalsAny(s.getScanidentify(), "ZK1521568970411545",
                                    "ZK1511568970369464", "ZK1491568970193028", "ZK1481568970138180",
                                    "ZK1531568970442358")).collect(Collectors.toList());
                        }
                        //如果工作状态是下班
                    } else {
                        qcEquipments = qcEquipments1;
                    }
                    //如果设备分类不是冰箱
                } else {
                    qcEquipments = qcEquipments1;
                }
                //如果设备分类是液氮罐
            } else {
                //如果角色类型是5
                if (StringUtils.equals(roleType, "5")) {
                    //助理下班需要巡检液氮罐胚胎二室 胚胎三室
                    //技术员巡检 胚胎一室
                    //如果工作状态是上班
                    if (StringUtils.equals(workStatus, "1")) {
                        //去qc_equipment表中查询出设备分类classifyId且是否可用为开启且创建时间小于等于开始时间的所有数据
                        qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                                .eq(QcEquipment::getClassifyId, classifyId)
                                .eq(QcEquipment::getEnable, 0)
                                .le(QcEquipment::getCreateTime, startTime));
                        //如果工作状态为下班
                    } else {
                        //去qc_equipment表中查询出设备分类classifyId且是否可用为开启且创建时间小于等于开始时间的所有数据
                        List<QcEquipment> qcEquipments1 = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                                .eq(QcEquipment::getClassifyId, classifyId)
                                .eq(QcEquipment::getEnable, 0)
                                .le(QcEquipment::getCreateTime, startTime));
                        //将之前查询出来的数据再过滤一下，过滤条件是位置是不等于胚胎库1的数据，
                        // 然后将过滤出来的数据转换成list集合赋值给最初我们创建的qcEquipments集合对象
                        qcEquipments = qcEquipments1.stream().filter(s -> !StringUtils.equals(s.getLocation(), "4")).collect(Collectors.toList());
                    }
                    //如果角色类型不为5的话
                } else {
                    //如果工作状态为上班
                    if (StringUtils.equals(workStatus, "1")) {
                        return null;
                        //如果工作状态为下班
                    } else {
                        //去qc_equipment表中查询出设备分类classifyId且是否可用为开启且创建时间小于等于开始时间的所有数据
                        List<QcEquipment> qcEquipments1 = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                                .eq(QcEquipment::getClassifyId, classifyId)
                                .eq(QcEquipment::getEnable, 0)
                                .le(QcEquipment::getCreateTime, startTime));
                        //将之前查询出来的数据再过滤一下，过滤条件是位置是等于胚胎库1的数据，
                        // 然后将过滤出来的数据转换成list集合赋值给最初我们创建的qcEquipments集合对象
                        qcEquipments = qcEquipments1.stream().filter(s -> StringUtils.equals(s.getLocation(), "4")).collect(Collectors.toList());
                    }
                }
            }
        }
        //如果qcEquipments集合为空
        if (CollectionUtils.isEmpty(qcEquipments)) {
            return null;
        }
        //将qcEquipments集合中每个下标的设备对象的id属性取出来封装到一个list集合里面
        List<Integer> collect2 = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        //将设备对象的id集合添加到qcRecordStatusModel对象的EqIds属性中
        qcRecordStatusModel.setEqIds(collect2);
        //通过qcRecordStatusModel查询出一个QcRecordStatus集合对象
        List<QcRecordStatus> allQcRecordStatus = qcEquipmentMapper.getAllQcRecordStatus(qcRecordStatusModel);
        return equipmentRecordServiceImplUtilService.inspectionStatus(allQcRecordStatus);
    }


    /**
     * 获取工作台工作状态
     *
     * @param qcRecordStatusModel
     * @return
     */
    @Override
    public List<QcRecordStatus> getWorkStatus(QcRecordStatusModel qcRecordStatusModel) {
        //获取开始时间
        String startTime = qcRecordStatusModel.getStartTime();
        //从qc_equipment表中查询出所有设备分类为工作台且是否可用为启用且创建时间小于等于开始时间的所有数据
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .eq(QcEquipment::getClassifyId, "9")
                .eq(QcEquipment::getEnable, 0)
                .le(QcEquipment::getCreateTime, startTime));
        //如果qcEquipments为空
        if (CollectionUtils.isEmpty(qcEquipments)) {
            return null;
        }
        //通过qcEquipments集合获取所有QcEquipment对象id属性组成的集合
        List<Integer> collect2 = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        //设置qcRecordStatusModel的设备id集合属性
        qcRecordStatusModel.setEqIds(collect2);
        //设置qcRecordStatusModel对象的工作状态为上班
        qcRecordStatusModel.setWorkStatus("1");
        //获取所有工作状态为上班的QcRecordStatus对象
        List<QcRecordStatus> workStatus = qcEquipmentMapper.getWorkStatus(qcRecordStatusModel);
        //设置qcRecordStatusModel对象的工作状态为下班
        qcRecordStatusModel.setWorkStatus("2");
        //获取所有工作状态为下班的QcRecordStatus对象
        List<QcRecordStatus> workStatus1 = qcEquipmentMapper.getWorkStatus(qcRecordStatusModel);
        return equipmentRecordServiceImplUtilService.workStatus(workStatus, workStatus1);
    }


    @Override
    public QcEquipmentRecord getWorkbenchOperationBatch(String eqId, String workType, String date) {
        List<QcEquipmentRecord> qcEquipmentRecordByType = qcEquipmentRecordMapper.getQcEquipmentRecordByType(date, eqId, workType);
        Map<String, List<QcEquipmentRecord>> collect = qcEquipmentRecordByType.stream().collect(Collectors.groupingBy(QcEquipmentRecord::getWorkbenchOperationBatch));
        Set<String> strings = collect.keySet();
        for (String s : strings) {
            List<QcEquipmentRecord> qcEquipmentRecords = collect.get(s);
            if (qcEquipmentRecords.size() == 1) {
                return qcEquipmentRecords.get(0);
            }
        }
        return null;
    }

    /**
     * 查询设备巡检记录详情
     *
     * @param qcRecordStatusModel
     * @return
     */
    @Override
    public List<QcEquipmentRecordModel> findEqDeatil(QcRecordStatusModel qcRecordStatusModel) {
        //根据封装的QcRecordStatusModel对象查询封装之后的所有符合条件的QcEquipmentRecordModel对象集合
        List<QcEquipmentRecordModel> eqDeatil = qcEquipmentMapper.findEqDeatil(qcRecordStatusModel);
        //如果eqDeatil集合不为空
        if (CollectionUtils.isNotEmpty(eqDeatil)) {
            //获取eqDeatil集合中的每个QcEquipmentRecordModel对象的id属性转换成一个由QcEquipmentRecordModel对象的id属性组成的set集合
            Set<Long> collect1 = eqDeatil.stream().map(QcEquipmentRecordModel::getId).collect(Collectors.toSet());
            //去qc_filestore表中查询所有设备记录类型为巡检且设备记录id对应collect1集合中值的且按照创建时间正序排列的数据集合，1为巡检，2为监测
            List<QcFilestore> list = qcFilestoreMapper.selectList(Wrappers.lambdaQuery(new QcFilestore()).eq(QcFilestore::getRecordType, "1")
                    .in(QcFilestore::getRecordId, collect1)
                    .orderByAsc(QcFilestore::getCreateTime));
            //根据list集合中的QcFilestore对象的设备记录id，将list集合转化成map集合类型，key是设备记录id，值是所有设备记录id和key相等的QcFilestore对象组成的list集合
            Map<Long, List<QcFilestore>> collect2 = list.stream().collect(Collectors.groupingBy(QcFilestore::getRecordId));
            //遍历eqDeatil集合，m代表集合中每个下标的QcEquipmentRecordModel对象
            eqDeatil.forEach(m -> {
                //获取collect2集合中键等于QcEquipmentRecordModel对象的id属性值得QcFilestore对象集合
                List<QcFilestore> list1 = collect2.get(m.getId());
                //如果list1不为空
                if (CollectionUtils.isNotEmpty(list1)) {
                    //将list1集合中没有下标中的当前对象的fileUrl不为空的对象过滤出来，转化成一个由其FileUrl属性组成的list集合
                    List<String> collect = list1.stream().filter(h -> StringUtils.isNotEmpty(h.getFileUrl())).map(QcFilestore::getFileUrl).collect(Collectors.toList());
                    //将处理的collect对象添加进QcEquipmentRecordModel对象的Images属性
                    m.setImages(collect);
                }
            });
            //通过eqDeatil集合对象生成一个set<String>集合对象,值为eqDeatil集合对象中每个下标的QcEquipmentRecordModel对象的创建人属性
            Set<String> collect = eqDeatil.stream().map(QcEquipmentRecordModel::getCreateBy).collect(Collectors.toSet());
            //通过用户id获取用户名称
            Map<String, String> allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(collect);
            //遍历eqDeatil集合
            eqDeatil.forEach(s -> {
                //获取每个下标对象的创建人属性
                String createBy = s.getCreateBy();
                //在allSysUserinfoByIds集合对象中找到key为创建人的值，该值就操作者的名称
                String createName = allSysUserinfoByIds.get(createBy);
                //将获取到的操作者名称添加进QcEquipmentRecordModel对象的CreateName属性
                s.setCreateName(createName);
            });
            //返回经过一系列操作的eqDeatil集合对象
            return eqDeatil;
        }
        return null;
    }

    /**
     * 获取工作台每日质控报表数据
     *
     * @param date
     * @param userId
     * @return
     */
    @Override
    public List<WorkbenchModel> getWorkbenchModelEveryDayForGZT(String date, String userId) {
        List<WorkbenchModel> listResult = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取所有工作台指定时间的维护记录集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForDay(date, "9");
        Map<Integer, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> userIds = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //将维护记录集合按设备id分组
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(QcMonitor::getEqId));
            userIds = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(userIds);
        }
        //获取操作类型是工作台且是传入日期当天的且操作的巡检记录是属于当前操作用户所在组员操作的巡检记录集合
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryDay(date, "9");
        if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
            //将获得的巡检记录按设备id分组，每一个id对应的就是这个工作台的巡检记录集合
            Map<Integer, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels.stream().collect(Collectors.groupingBy(QcEquipmentRecordModel::getEqId));
            Set<Integer> integers = collect.keySet();
            Map<Integer, List<WorkbenchModel>> map = new HashMap<>();
            integers.forEach(key -> {
                List<WorkbenchModel> list = new ArrayList<>();
                //获取当前id的值和key相等的工作台巡检数据集合
                List<QcEquipmentRecordModel> modelList = collect.get(key);
                //遍历该集合，判断工作台巡检数据的操作类型，是操作前还是操作后
                modelList.forEach(model -> {
                    WorkbenchModel workbenchModel = new WorkbenchModel();
                    //获取工作台的操作类型
                    String type = model.getWorkbenchOperationType();
                    //获取工作台巡检记录是操作前还是操作后
                    String workbenchOperationPattern = model.getWorkbenchOperationPattern();
                    //表示工作类型是ICSI
                    if (StringUtils.equals("1", type)) {
                        //表示是工作前
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("1");
                            workbenchModel.setStatus("1");
                            //设置工作台的操作批次
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("ICSI");
                            workbenchModel.setOilMassBegin(model.getOilMass());
                            workbenchModel.setMotionArmBegin(model.getMotionArm());
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setMineralOilBegin(model.getMineralOil());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                            //表示是工作后
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("1");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("ICSI");
                            workbenchModel.setOilMassEnd(model.getOilMass());
                            workbenchModel.setMotionArmEnd(model.getMotionArm());
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setMineralOilEnd(model.getMineralOil());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                        //表示工作类型是AS
                    } else if (StringUtils.equals("2", type)) {
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("2");
                            workbenchModel.setStatus("1");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("AS");
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setLaserLightSourceBegin(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionBegin(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("2");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("AS");
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setLaserLightSourceEnd(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionEnd(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                        //表示工作类型是胚胎活检
                    } else if (StringUtils.equals("3", type)) {
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("3");
                            workbenchModel.setStatus("1");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("胚胎活检");
                            workbenchModel.setOilMassBegin(model.getOilMass());
                            workbenchModel.setMotionArmBegin(model.getMotionArm());
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setLaserLightSourceBegin(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionBegin(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("3");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("胚胎活检");
                            workbenchModel.setOilMassEnd(model.getOilMass());
                            workbenchModel.setMotionArmEnd(model.getMotionArm());
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setLaserLightSourceEnd(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionEnd(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                        //表示工作类型是胚胎观察
                    } else if (StringUtils.equals("4", type)) {
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("4");
                            workbenchModel.setStatus("1");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("胚胎观察");
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("4");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("胚胎观察");
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                    }
                });
                map.put(key, list);
            });
            Set<Integer> keySet = map.keySet();
            keySet.forEach(k -> {
                //获取每个工作台的操作数据
                List<WorkbenchModel> list1 = map.get(k);
                //将封装之后的数据按操作类型分组
                Map<String, List<WorkbenchModel>> listMap = list1.stream().collect(Collectors.groupingBy(WorkbenchModel::getType));
                Set<String> typeSet = listMap.keySet();
                typeSet.forEach(type -> {
                    //获取每一种操作类型对应的数据
                    List<WorkbenchModel> typeList = listMap.get(type);
                    //将每种操作类型对应的数据再按操作批次分组
                    Map<String, List<WorkbenchModel>> collect1 = typeList.stream().collect(Collectors.groupingBy(WorkbenchModel::getWorkbenchOperationBatch));
                    Set<String> set = collect1.keySet();
                    set.forEach(s -> {
                        //获取每种操作类型相同批次的数据，这时的数据里面开始将操作前操作后的数据整合成一条数据
                        List<WorkbenchModel> list2 = collect1.get(s);
                        WorkbenchModel wm = new WorkbenchModel();
                        list2.forEach(model2 -> {
                            wm.setEqId(model2.getEqId());
                            wm.setDeviceName(model2.getDeviceName());
                            wm.setDay(model2.getDay());
                            String type1 = model2.getType();
                            String status = model2.getStatus();
                            //表示是ICSI
                            if (StringUtils.equals("1", type1)) {
                                //操作前
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("ICSI");
                                    wm.setOilMassBegin(model2.getOilMassBegin());
                                    wm.setMotionArmBegin(model2.getMotionArmBegin());
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setMineralOilBegin(model2.getMineralOilBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                    //操作后
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("ICSI");
                                    wm.setOilMassEnd(model2.getOilMassEnd());
                                    wm.setMotionArmEnd(model2.getMotionArmEnd());
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setMineralOilEnd(model2.getMineralOilEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            } else if (StringUtils.equals("2", type1)) {
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("AS");
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setLaserLightSourceBegin(model2.getLaserLightSourceBegin());
                                    wm.setLaserFocusPositionBegin(model2.getLaserFocusPositionBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("AS");
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setLaserLightSourceEnd(model2.getLaserLightSourceEnd());
                                    wm.setLaserFocusPositionEnd(model2.getLaserFocusPositionEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            } else if (StringUtils.equals("3", type1)) {
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("胚胎活检");
                                    wm.setOilMassBegin(model2.getOilMassBegin());
                                    wm.setMotionArmBegin(model2.getMotionArmBegin());
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setLaserLightSourceBegin(model2.getLaserLightSourceBegin());
                                    wm.setLaserFocusPositionBegin(model2.getLaserFocusPositionBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("胚胎活检");
                                    wm.setOilMassEnd(model2.getOilMassEnd());
                                    wm.setMotionArmEnd(model2.getMotionArmEnd());
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setLaserLightSourceEnd(model2.getLaserLightSourceEnd());
                                    wm.setLaserFocusPositionEnd(model2.getLaserFocusPositionEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            } else if (StringUtils.equals("4", type1)) {
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("胚胎观察");
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("胚胎观察");
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            }
                        });
                        listResult.add(wm);
                    });
                });
            });
            setRecordAndIsSignatureInGZZ(listResult, qcMonitorsMap, null, allSysUserinfoByIds);
            //设置操作人姓名
            equipmentRecordServiceImplUtilService.setWorkbenchModelUserName(listResult);
            return listResult;
        } else {
            return null;
        }
    }


    /**
     * 设置工作台巡检记录中的维护记录属性和是否签章属性
     *
     * @param list
     * @param map
     */
    private void setRecordAndIsSignatureInGZZ(List<WorkbenchModel> list,
                                              Map<Integer, List<QcMonitor>> map,
                                              Map<String, List<QcMonitor>> map2,
                                              Map<String, String> allSysUserinfoByIds) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, List<DigitalSignature>> digitalSignatureMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(list)) {
            List<String> collect = list.stream().map(WorkbenchModel::getIdBegin).map(String::valueOf).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(collect)) {
                List<DigitalSignature> digitalSignatures = digitalSignatureMapper.selectList(Wrappers.lambdaQuery(new DigitalSignature())
                        .in(DigitalSignature::getWorkOnRecordId, collect));
                digitalSignatureMap = digitalSignatures.stream().collect(Collectors.groupingBy(DigitalSignature::getWorkOnRecordId));
            }
        }
        for (int m = 0; m < list.size(); m++) {
            Long idBegin = list.get(m).getIdBegin();
            if (idBegin != null) {
                DigitalSignature isSignature = new DigitalSignature();
                List<DigitalSignature> digitalSignatures = digitalSignatureMap.get(String.valueOf(idBegin));
                if (CollectionUtils.isNotEmpty(digitalSignatures)) {
                    isSignature = digitalSignatures.get(0);
                }
                if (isSignature != null) {
                    list.get(m).setSignatureId(isSignature.getSignatureId());
                    list.get(m).setIsSignature(isSignature.getIsSignature());
                    list.get(m).setSelfCheck(isSignature.getSelfCheck());
                    list.get(m).setChecker(isSignature.getChecker());
                }
            }
        }

        for (int i = 0; i < list.size(); i++) {
            List<Long> ids = new ArrayList<>();
            List<QcMonitor> qcMonitors = null;
            StringBuffer sb = new StringBuffer();
            if (map != null) {
                Integer eqId = list.get(i).getEqId();
                //获取当前设备对应的维护记录集合
                qcMonitors = map.get(eqId);
            } else if (map2 != null) {
                String day = list.get(i).getDay();
                qcMonitors = map2.get(day);
            }
            if (CollectionUtils.isNotEmpty(qcMonitors)) {
                for (int n = 0; n < qcMonitors.size(); n++) {
                    Long id = qcMonitors.get(n).getId();
                    ids.add(id);
                    String maintenanceProjects = qcMonitors.get(n).getMaintenanceProjects();
                    String maintenanceProjectsName = null;
                    //表示是常规维护
                    if (StringUtils.isNotEmpty(maintenanceProjects)) {
                        if (StringUtils.equals("1", maintenanceProjects)) {
                            maintenanceProjectsName = "清洁";
                        } else if (StringUtils.equals("2", maintenanceProjects)) {
                            maintenanceProjectsName = "定期保养";
                        } else if (StringUtils.equals("3", maintenanceProjects)) {
                            maintenanceProjectsName = "更换耗材";
                        } else if (StringUtils.equals("4", maintenanceProjects)) {
                            maintenanceProjectsName = "故障维修";
                        } else if (StringUtils.equals("5", maintenanceProjects)) {
                            maintenanceProjectsName = "加水";
                        }
                        String remark = qcMonitors.get(n).getRemark();
                        Date maintainTime = qcMonitors.get(n).getMaintainTime();
                        String maintainTimeStr = sdf.format(maintainTime);
                        String createName = allSysUserinfoByIds.get(qcMonitors.get(n).getCreateBy());
                        sb.append("维护项目：" + maintenanceProjectsName + "，").append("保养时间：" + maintainTimeStr + "，")
                                .append("维护人：" + createName);
                        if (StringUtils.isNotEmpty(remark)) {
                            sb.append("，备注：" + remark);
                        }
                        sb.append(";");
                        //工作台温台中的维护
                    } else {
                        String isCalibration = qcMonitors.get(n).getIsCalibration();
                        String isCalibrationStr = null;
                        if (StringUtils.isNotEmpty(isCalibration)) {
                            if (StringUtils.equals("1", isCalibration)) {
                                isCalibrationStr = "已校准";
                            } else if (StringUtils.equals("2", isCalibration)) {
                                isCalibrationStr = "未校准";
                            }
                            String remark = qcMonitors.get(n).getRemark();
                            Date nextCalibrationTime = qcMonitors.get(n).getNextCalibrationTime();
                            String nextCalibrationTimeStr = sdf.format(nextCalibrationTime);
                            Date createTime = qcMonitors.get(n).getCreateTime();
                            String createTimeStr = sdf.format(createTime);
                            String createName = allSysUserinfoByIds.get(qcMonitors.get(n).getCreateBy());
                            sb.append("维护项目：工作台温台，" + "是否校准：" + isCalibrationStr + "，")
                                    .append("维护时间：" + createTimeStr + "，")
                                    .append("下次维护时间：" + nextCalibrationTimeStr + "，")
                                    .append("维护人：" + createName);
                            if (StringUtils.isNotEmpty(remark)) {
                                sb.append("，备注：" + remark);
                            }
                            sb.append(";");
                        }
                    }
                    String str = sb.toString();
                    list.get(i).setMaintenanceRecord(str);
                    list.get(i).setQcMonitorIds(ids);
                }
            }
        }
    }

    /**
     * 获取工作台每月质控报表数据
     *
     * @param eqId
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<WorkbenchModel> getWorkbenchModelEveryMonthForGZT(int eqId, String startTime, String endTime) {
        List<WorkbenchModel> listResult = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //获取所有工作台指定时间的维护记录集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForMonth(eqId, startTime, endTime);
        Map<String, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> userIds = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //将维护记录集合按设备id分组
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd").format(q.getCreateTime())));
            userIds = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(userIds);
        }
        //获取操作类型是工作台且是传入日期当天的且操作的巡检记录是属于当前操作用户所在组员操作的巡检记录集合
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
        if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
            //将获得的巡检记录按日期分组，每一个日期对应的就是这个工作台当天的巡检记录集合
            Map<String, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels.stream().collect(Collectors.groupingBy(m -> new SimpleDateFormat("yyyy-MM-dd").format(m.getCreateTime())));
            Set<String> timeStrs2 = collect.keySet();
            List<String> timeStrs = timeStrs2.stream().sorted().collect(Collectors.toList());
            Map<String, List<WorkbenchModel>> map = new HashMap<>();
            timeStrs.forEach(timeStr -> {
                List<WorkbenchModel> list = new ArrayList<>();
                //获取当前timeStr指定日期的巡检记录数据集合
                List<QcEquipmentRecordModel> modelList = collect.get(timeStr);
                //遍历该集合，判断工作台巡检数据的操作类型，是操作前还是操作后
                modelList.forEach(model -> {
                    WorkbenchModel workbenchModel = new WorkbenchModel();
                    //获取工作台的操作类型
                    String type = model.getWorkbenchOperationType();
                    //获取工作台巡检记录是操作前还是操作后
                    String workbenchOperationPattern = model.getWorkbenchOperationPattern();
                    //表示工作类型是ICSI
                    if (StringUtils.equals("1", type)) {
                        //表示是工作前
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("1");
                            workbenchModel.setStatus("1");
                            //设置工作台的操作批次
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("ICSI");
                            workbenchModel.setOilMassBegin(model.getOilMass());
                            workbenchModel.setMotionArmBegin(model.getMotionArm());
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setMineralOilBegin(model.getMineralOil());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                            //表示是工作后
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("1");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("ICSI");
                            workbenchModel.setOilMassEnd(model.getOilMass());
                            workbenchModel.setMotionArmEnd(model.getMotionArm());
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setMineralOilEnd(model.getMineralOil());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                        //表示工作类型是AS
                    } else if (StringUtils.equals("2", type)) {
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("2");
                            workbenchModel.setStatus("1");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("AS");
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setLaserLightSourceBegin(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionBegin(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("2");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("AS");
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setLaserLightSourceEnd(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionEnd(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                        //表示工作类型是胚胎活检
                    } else if (StringUtils.equals("3", type)) {
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("3");
                            workbenchModel.setStatus("1");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("胚胎活检");
                            workbenchModel.setOilMassBegin(model.getOilMass());
                            workbenchModel.setMotionArmBegin(model.getMotionArm());
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setLaserLightSourceBegin(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionBegin(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("3");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("胚胎活检");
                            workbenchModel.setOilMassEnd(model.getOilMass());
                            workbenchModel.setMotionArmEnd(model.getMotionArm());
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setLaserLightSourceEnd(model.getLaserLightSource());
                            workbenchModel.setLaserFocusPositionEnd(model.getLaserFocusPosition());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                        //表示工作类型是胚胎观察
                    } else if (StringUtils.equals("4", type)) {
                        if (StringUtils.equals("1", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("4");
                            workbenchModel.setStatus("1");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setBeginPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeBegin("胚胎观察");
                            workbenchModel.setWenBoardBegin(model.getWenBoard());
                            workbenchModel.setLightSourceBegin(model.getLightSource());
                            workbenchModel.setCheckingPeopleBegin(model.getCreateBy());
                            workbenchModel.setIdBegin(model.getId());
                            list.add(workbenchModel);
                        } else if (StringUtils.equals("2", workbenchOperationPattern)) {
                            workbenchModel.setEqId(model.getEqId());
                            workbenchModel.setDeviceName(model.getDeviceName());
                            String str = sdf.format(model.getCreateTime());
                            String day = str.substring(0, 10);
                            String time = str.substring(str.length() - 8);
                            workbenchModel.setDay(day);
                            workbenchModel.setType("4");
                            workbenchModel.setStatus("2");
                            workbenchModel.setWorkbenchOperationBatch(model.getWorkbenchOperationBatch());
                            workbenchModel.setEndPollingTime(time);
                            workbenchModel.setWorkbenchOperationTypeEnd("胚胎观察");
                            workbenchModel.setWenBoardEnd(model.getWenBoard());
                            workbenchModel.setLightSourceEnd(model.getLightSource());
                            workbenchModel.setCheckingPeopleEnd(model.getCreateBy());
                            workbenchModel.setIdEnd(model.getId());
                            list.add(workbenchModel);
                        }
                    }
                });
                map.put(timeStr, list);
            });
            Set<String> keySet2 = map.keySet();
            List<String> keySet = keySet2.stream().sorted().collect(Collectors.toList());
            keySet.forEach(k -> {
                //获取每个工作台的操作数据
                List<WorkbenchModel> list1 = map.get(k);
                //将封装之后的数据按操作类型分组
                Map<String, List<WorkbenchModel>> listMap = list1.stream().collect(Collectors.groupingBy(WorkbenchModel::getType));
                Set<String> typeSet = listMap.keySet();
                typeSet.forEach(type -> {
                    //获取每一种操作类型对应的数据
                    List<WorkbenchModel> typeList = listMap.get(type);
                    //将每种操作类型对应的数据再按操作批次分组
                    Map<String, List<WorkbenchModel>> collect1 = typeList.stream().collect(Collectors.groupingBy(WorkbenchModel::getWorkbenchOperationBatch));
                    Set<String> set = collect1.keySet();
                    set.forEach(s -> {
                        //获取每种操作类型相同批次的数据，这时的数据里面开始将操作前操作后的数据整合成一条数据
                        List<WorkbenchModel> list2 = collect1.get(s);
                        WorkbenchModel wm = new WorkbenchModel();
                        list2.forEach(model2 -> {
                            wm.setEqId(model2.getEqId());
                            wm.setDeviceName(model2.getDeviceName());
                            wm.setDay(model2.getDay());
                            String type1 = model2.getType();
                            String status = model2.getStatus();
                            //表示是ICSI
                            if (StringUtils.equals("1", type1)) {
                                //操作前
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("ICSI");
                                    wm.setOilMassBegin(model2.getOilMassBegin());
                                    wm.setMotionArmBegin(model2.getMotionArmBegin());
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setMineralOilBegin(model2.getMineralOilBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                    //操作后
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("ICSI");
                                    wm.setOilMassEnd(model2.getOilMassEnd());
                                    wm.setMotionArmEnd(model2.getMotionArmEnd());
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setMineralOilEnd(model2.getMineralOilEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            } else if (StringUtils.equals("2", type1)) {
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("AS");
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setLaserLightSourceBegin(model2.getLaserLightSourceBegin());
                                    wm.setLaserFocusPositionBegin(model2.getLaserFocusPositionBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("AS");
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setLaserLightSourceEnd(model2.getLaserLightSourceEnd());
                                    wm.setLaserFocusPositionEnd(model2.getLaserFocusPositionEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            } else if (StringUtils.equals("3", type1)) {
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("胚胎活检");
                                    wm.setOilMassBegin(model2.getOilMassBegin());
                                    wm.setMotionArmBegin(model2.getMotionArmBegin());
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setLaserLightSourceBegin(model2.getLaserLightSourceBegin());
                                    wm.setLaserFocusPositionBegin(model2.getLaserFocusPositionBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("胚胎活检");
                                    wm.setOilMassEnd(model2.getOilMassEnd());
                                    wm.setMotionArmEnd(model2.getMotionArmEnd());
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setLaserLightSourceEnd(model2.getLaserLightSourceEnd());
                                    wm.setLaserFocusPositionEnd(model2.getLaserFocusPositionEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            } else if (StringUtils.equals("4", type1)) {
                                if (StringUtils.equals("1", status)) {
                                    wm.setBeginPollingTime(model2.getBeginPollingTime());
                                    wm.setWorkbenchOperationTypeBegin("胚胎观察");
                                    wm.setWenBoardBegin(model2.getWenBoardBegin());
                                    wm.setLightSourceBegin(model2.getLightSourceBegin());
                                    wm.setCheckingPeopleBegin(model2.getCheckingPeopleBegin());
                                    wm.setIdBegin(model2.getIdBegin());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                } else if (StringUtils.equals("2", status)) {
                                    wm.setEndPollingTime(model2.getEndPollingTime());
                                    wm.setWorkbenchOperationTypeEnd("胚胎观察");
                                    wm.setWenBoardEnd(model2.getWenBoardEnd());
                                    wm.setLightSourceEnd(model2.getLightSourceEnd());
                                    wm.setCheckingPeopleEnd(model2.getCheckingPeopleEnd());
                                    wm.setIdEnd(model2.getIdEnd());
                                    wm.setWorkbenchOperationBatch(model2.getWorkbenchOperationBatch());
                                }
                            }
                        });
                        listResult.add(wm);
                    });
                });
            });
            setRecordAndIsSignatureInGZZ(listResult, null, qcMonitorsMap, allSysUserinfoByIds);
            //设置操作人姓名
            equipmentRecordServiceImplUtilService.setWorkbenchModelUserName(listResult);
            return listResult;
        } else {
            return null;
        }
    }

    /**
     * 获取环境每日质控报表数据
     *
     * @param date
     * @param userId
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryDayForHJ(String date, String userId) {
        //获取环境检测数据集合
        Map<String, List<Environmentmv>> environmentMvDay = iEnvironmentmvService.selectEnvironmentmvday(date);
        if (null == environmentMvDay) {
            environmentMvDay = iEnvironmentmvService.selectEnvironmentmvday(FIXEDTIME);
        }
        //查询所有设备类型相等的设备集合
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .eq(QcEquipment::getEnable, "0")
                .eq(QcEquipment::getClassifyId, "7"));
        //获取类型相等的设备id集合
        List<Integer> integerList = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        //因为目前业务只需要显示培养室1和2，所以需要将其他设备的id去掉
        List<Integer> collect1 = integerList.stream().filter(Objects::nonNull).collect(Collectors.toList());
        //获取设备id对应设备名称的map集合
        Map<Integer, String> eqNameMap = equipmentRecordServiceImplUtilService.getEqNameMap(collect1);
        //获取所有环境指定时间的回风维护记录集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForDayInHF(date, "7");
        Map<Integer, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(QcMonitor::getEqId));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合

            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryDayInHJ(date, "7");
        for (int n = 0; n < collect1.size(); n++) {
            Integer eqId = collect1.get(n);
            List<QualityControlReport> list = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            String deviceName = eqNameMap.get(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(date);
            for (int i = 1; i <= 4; i++) {
                QualityControlReport qualityControlReport = new QualityControlReport();
                qualityControlReport.setTime((i - 1) * 6 + "-" + i * 6);
                list.add(qualityControlReport);
            }
            //如果获取的检测记录数据有数据就将其数据的值set到qualityControlReport对象对应的属性中
            if (environmentMvDay != null) {
                List<Environmentmv> environmentmvs = environmentMvDay.get(String.valueOf(eqId));
                if (CollectionUtils.isNotEmpty(environmentmvs)) {
                    environmentmvs.forEach(env -> {
                        String timeInterval = env.getTimeInterval();
                        if (StringUtils.equals("1", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list, env, 0);
                        } else if (StringUtils.equals("2", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list, env, 1);
                        } else if (StringUtils.equals("3", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list, env, 2);
                        } else if (StringUtils.equals("4", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list, env, 3);
                        }
                    });
                }
            }
            //如果巡检记录有值
            if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
                Map<Integer, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels
                        .stream().collect(Collectors.groupingBy(QcEquipmentRecordModel::getEqId));
                List<QcEquipmentRecordModel> modelList = collect.get(eqId);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        Date createTime = qcr.getCreateTime();
                        EquipmentRecordServiceImplUtil.determineSetPropertiesForHJ(qcr, createTime, list);
                    });
                }
            }
            qualityControlReportList.setQcrs(list);
            equipmentRecordServiceImplUtilService.setRecordForHJ(qualityControlReportList.getEqId(), date, qualityControlReportList, qcMonitorsMap, null, "day", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }


    /**
     * 获取胚胎库每日质控报表数据
     *
     * @param date
     * @param userId
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryDayForPTK(String date, String userId) {


        //查询所有设备类型相等的设备集合
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .eq(QcEquipment::getEnable, "0")
                .eq(QcEquipment::getClassifyId, "2"));
        //获取类型相等的设备id集合
        List<Integer> integerList = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        Map<Integer, String> eqNameMap = equipmentRecordServiceImplUtilService.getEqNameMap(integerList);
        //获取所有胚胎库指定时间的维护记录集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForDay(date, "2");
        Map<Integer, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(QcMonitor::getEqId));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryDay(date, "2");
        for (int n = 0; n < integerList.size(); n++) {
            Integer eqId = integerList.get(n);
            List<QualityControlReport> list = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            String deviceName = eqNameMap.get(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(date);
            QualityControlReport qualityControlReport = new QualityControlReport();
            list.add(qualityControlReport);
            if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
                Map<Integer, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels
                        .stream().collect(Collectors.groupingBy(QcEquipmentRecordModel::getEqId));
                List<QcEquipmentRecordModel> modelList = collect.get(eqId);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        String workStatus = qcr.getWorkStatus();
                        if (StringUtils.isNotEmpty(workStatus)) {
                            //表示上班巡检
                            if (StringUtils.equals("1", workStatus)) {
                                list.get(0).setIdOnWork(String.valueOf(qcr.getId()));
                                list.get(0).setInspectionTimeOnWork(qcr.getCreateTime());
                                list.get(0).setCheckingPeopleOnWork(qcr.getCreateBy());
                                list.get(0).setMonitoringSystemOnWork(qcr.getMonitoringSystem());
                                list.get(0).setCanisterLockOnWork(qcr.getCanisterLock());
                                list.get(0).setCanisterTemperatureOnWork(qcr.getCanisterTemperature());
                                list.get(0).setTankTemperatureInfoOnWork(qcr.getTankTemperatureInfo());
                                list.get(0).setTankLockInfoOnWork(qcr.getTankLockInfo());
                                //表示下班巡检
                            } else if (StringUtils.equals("2", workStatus)) {
                                list.get(0).setIdOffWork(qcr.getId());
                                list.get(0).setInspectionTimeOffWork(qcr.getCreateTime());
                                list.get(0).setCheckingPeopleOffWork(qcr.getCreateBy());
                                list.get(0).setMonitoringSystemOffWork(qcr.getMonitoringSystem());
                                list.get(0).setCanisterLockOffWork(qcr.getCanisterLock());
                                list.get(0).setCanisterTemperatureOffWork(qcr.getCanisterTemperature());
                                list.get(0).setTankTemperatureInfoOffWork(qcr.getTankTemperatureInfo());
                                list.get(0).setTankLockInfoOffWork(qcr.getTankLockInfo());
                            }
                        }
                    });
                }
            }
            qualityControlReportList.setQcrs(list);
            //设置维护记录属性值和是否添加液氮的属性值
            equipmentRecordServiceImplUtilService.setRecord(qualityControlReportList.getEqId(), date, qualityControlReportList, qcMonitorsMap, null, "day", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }


    /**
     * 获取离心机或者工作站每日质控报表数据
     *
     * @param date
     * @param userId
     * @param classifyId 11表示用于离心机，5表示用于工作站
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryDayForLXJOrGZZ(String date, String userId, String classifyId) {
        //查询所有设备类型相等的设备集合
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .eq(QcEquipment::getEnable, "0")
                .eq(QcEquipment::getClassifyId, classifyId));
        //获取类型相等的设备id集合
        List<Integer> integerList = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        //获取设备id对应设备名称的map集合
        Map<Integer, String> eqNameMap = equipmentRecordServiceImplUtilService.getEqNameMap(integerList);
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForDay(date, classifyId);
        Map<Integer, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(QcMonitor::getEqId));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }

        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryDay(date, classifyId);
        for (int n = 0; n < integerList.size(); n++) {
            Integer eqId = integerList.get(n);
            List<QualityControlReport> list = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            String deviceName = eqNameMap.get(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(date);
            QualityControlReport qualityControlReport = new QualityControlReport();
            list.add(qualityControlReport);
            if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
                Map<Integer, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels
                        .stream().collect(Collectors.groupingBy(QcEquipmentRecordModel::getEqId));
                List<QcEquipmentRecordModel> modelList = collect.get(eqId);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        String workStatus = qcr.getWorkStatus();
                        if (StringUtils.isNotEmpty(workStatus)) {
                            //表示上班巡检
                            if (StringUtils.equals("1", workStatus)) {
                                list.get(0).setIdOnWork(String.valueOf(qcr.getId()));
                                list.get(0).setInspectionTimeOnWork(qcr.getCreateTime());
                                list.get(0).setRunningStatusOnWork(qcr.getRunningStatus());
                                list.get(0).setCheckingPeopleOnWork(qcr.getCreateBy());
                                //表示下班巡检
                            } else if (StringUtils.equals("2", workStatus)) {
                                list.get(0).setIdOffWork(qcr.getId());
                                list.get(0).setInspectionTimeOffWork(qcr.getCreateTime());
                                list.get(0).setRunningStatusOffWork(qcr.getRunningStatus());
                                list.get(0).setCheckingPeopleOffWork(qcr.getCreateBy());
                            }
                        }
                    });
                }
            }
            qualityControlReportList.setQcrs(list);
            equipmentRecordServiceImplUtilService.setRecord(qualityControlReportList.getEqId(), date, qualityControlReportList, qcMonitorsMap, null, "day", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }

    /**
     * 获取倒置显微镜每日质控报表数据
     *
     * @param date
     * @param userId
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryDayForXWJ(String date, String userId) {
        //查询所有设备类型相等的设备集合
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .eq(QcEquipment::getEnable, "0")
                .eq(QcEquipment::getClassifyId, "6"));
        //获取类型相等的设备id集合
        List<Integer> collect1 = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        //获取设备id对应设备名称的map集合
        Map<Integer, String> eqNameMap = equipmentRecordServiceImplUtilService.getEqNameMap(collect1);
        Map<Integer, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        //获取所有显微镜指定时间的维护记录集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForDay(date, "6");
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(QcMonitor::getEqId));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryDay(date, "6");
        for (int n = 0; n < collect1.size(); n++) {
            Integer eqId = collect1.get(n);
            List<QualityControlReport> list = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            String deviceName = eqNameMap.get(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(date);
            QualityControlReport qualityControlReport = new QualityControlReport();
            list.add(qualityControlReport);
            if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
                Map<Integer, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels.
                        stream().collect(Collectors.groupingBy(QcEquipmentRecordModel::getEqId));
                List<QcEquipmentRecordModel> modelList = collect.get(eqId);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        String workStatus = qcr.getWorkStatus();
                        if (StringUtils.isNotEmpty(workStatus)) {
                            //表示上班巡检
                            if (StringUtils.equals("1", workStatus)) {
                                list.get(0).setIdOnWork(String.valueOf(qcr.getId()));
                                list.get(0).setInspectionTimeOnWork(qcr.getCreateTime());
                                list.get(0).setRunningStatusOnWork(qcr.getRunningStatus());
                                list.get(0).setRemarkOnWork(qcr.getRemark());
                                list.get(0).setCheckingPeopleOnWork(qcr.getCreateBy());
                                list.get(0).setRemarkOnWork(qcr.getRemark());
                                //表示下班巡检
                            } else if (StringUtils.equals("2", workStatus)) {
                                list.get(0).setIdOffWork(qcr.getId());
                                list.get(0).setInspectionTimeOffWork(qcr.getCreateTime());
                                list.get(0).setRunningStatusOffWork(qcr.getRunningStatus());
                                list.get(0).setRemarkOffWork(qcr.getRemark());
                                list.get(0).setCheckingPeopleOffWork(qcr.getCreateBy());
                                list.get(0).setRemarkOffWork(qcr.getRemark());
                            }
                        }
                    });
                }
            }
            qualityControlReportList.setQcrs(list);
            equipmentRecordServiceImplUtilService.setRecordInXWJ(qualityControlReportList.getEqId(), date, qualityControlReportList, qcMonitorsMap, null, "day", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }


    public List<QualityControlReportList> createQualityControlReportEveryDayForPYX(List<IncubSnapshotInfo> incubSnapshotInfos) {
        List<QualityControlReportList> qualityControlReportLists = new ArrayList<>();
        for (IncubSnapshotInfo qualityControlReportList : incubSnapshotInfos) {
            QualityControlReportList incubSnapshotInfo = new QualityControlReportList();
            incubSnapshotInfo.setEqId(Integer.parseInt(qualityControlReportList.getEqId()));
            incubSnapshotInfo.setDeviceName(qualityControlReportList.getDeviceName());
            incubSnapshotInfo.setDate(qualityControlReportList.getDate());
            String qcrs = qualityControlReportList.getQcrs();
            if (StringUtils.isNotEmpty(qcrs)) {
                JSONArray jsonArrays = JSONUtil.parseArray(qcrs);
                List<QualityControlReport> qualityControlReports = jsonArrays.toList(QualityControlReport.class);
                incubSnapshotInfo.setQcrs(qualityControlReports);
            }
            incubSnapshotInfo.setMaintenanceRecord(qualityControlReportList.getMaintenanceRecord());
            String qcMonitorIds = qualityControlReportList.getQcMonitorIds();
            if (StringUtils.isNotEmpty(qcMonitorIds)) {
                JSONArray jsonArrays = JSONUtil.parseArray(qcMonitorIds);
                List<Long> longs = jsonArrays.toList(Long.class);
                incubSnapshotInfo.setQcMonitorIds(longs);
            }
            incubSnapshotInfo.setSignatureId(qualityControlReportList.getSignatureId());
            incubSnapshotInfo.setIsSignature(qualityControlReportList.getIsSignature());
            incubSnapshotInfo.setSelfCheck(qualityControlReportList.getSelfCheck());
            incubSnapshotInfo.setChecker(qualityControlReportList.getChecker());
            incubSnapshotInfo.setIsAddLiquidNitrogen(qualityControlReportList.getIsAddLiquidNitrogen());
            qualityControlReportLists.add(incubSnapshotInfo);

        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(qualityControlReportLists);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(qualityControlReportLists);
        return qualityControlReportLists;
    }

    public List<QualityControlReportList> createQualityControlDataPYX(List<IncubSnapshotInfo> incubSnapshotInfos, List<QcEquipment> qcEquipment) {
        Set<Integer> deviceIdSet = qcEquipment.stream()
                .map(QcEquipment::getId)
                .collect(Collectors.toSet());
        // 使用 Map 来去重，以 eqId 为 key
        Map<Integer, QualityControlReportList> resultMap = new HashMap<>();
        for (IncubSnapshotInfo snapshotInfo : incubSnapshotInfos) {
            String eqIdStr = snapshotInfo.getEqId();
            if (eqIdStr != null && !eqIdStr.trim().isEmpty()) {
                    int eqId = Integer.parseInt(eqIdStr.trim());
                    if (deviceIdSet.contains(eqId) && !resultMap.containsKey(eqId)) {
                        QualityControlReportList report = new QualityControlReportList();
                        report.setEqId(eqId);
                        report.setDeviceName(snapshotInfo.getDeviceName());
                        report.setDate(snapshotInfo.getDate());
                        String qcrs = snapshotInfo.getQcrs();
                        if (StringUtils.isNotEmpty(qcrs)) {
                            JSONArray jsonArrays = JSONUtil.parseArray(qcrs);
                            List<QualityControlReport> qualityControlReports = jsonArrays.toList(QualityControlReport.class);
                            report.setQcrs(qualityControlReports);
                        }
                        resultMap.put(eqId, report);
                    }
            }
        }
        List<QualityControlReportList> qualityControlReportLists = new ArrayList<>(resultMap.values());
        return qualityControlReportLists;
    }

    @Override
    public List<QualityControlReportList> getQualityControlReportEveryDayForPYXNew(String date, String userId) {
        List<IncubSnapshotInfo> incubSnapshotInfos = incubSnapshotMapper.selectByDate(DateUtil.formatDateString(date));
        if (CollectionUtils.isNotEmpty(incubSnapshotInfos)) {
            return createQualityControlReportEveryDayForPYX(incubSnapshotInfos);
        }
        Map<String, List<IncubModel>> incubModelMaps = iIncubatormvService.selectIncubdayNew(date);
        if (null == incubModelMaps) {
            incubModelMaps = iIncubatormvService.selectIncubdayNew(FIXEDTIME);
        }
        //查询所有设备类型相等的设备集合
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .eq(QcEquipment::getEnable, "0")
                .eq(QcEquipment::getClassifyId, "4")
                .orderByAsc(QcEquipment::getDeviceName));
        //获取类型相等的设备id集合
        Map<Integer, List<QcEquipment>> eqMap = qcEquipments.stream().collect(Collectors.groupingBy(QcEquipment::getId));
        //获取所有培养箱指定时间的维护记录集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForDay(date, "4");
        Map<Integer, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //将qcMonitors转化成以冰箱id为键，所有冰箱id等于键的QcMonitor对象的集合的map结构
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(QcMonitor::getEqId));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        //获取检测数据集合
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryDay(date, "4");
        List<QualityControlReportList> collecter = new ArrayList<>();

        Map<Integer, List<QcMonitor>> finalQcMonitorsMap = qcMonitorsMap;
        Map<String, String> finalAllSysUserinfoByIds = allSysUserinfoByIds;
        Map<String, List<IncubModel>> finalIncubModelMaps = incubModelMaps;
        eqMap.forEach((k, v) -> {
            QcEquipment qcEquipment = v.get(0);
            List<QualityControlReport> list = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(qcEquipment.getId());
            String deviceName = qcEquipment.getDeviceName();
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(date);
            //获取监控数据
            List<IncubModel> list1 = finalIncubModelMaps.get(String.valueOf(qcEquipment.getId()));
            for (int i = 1; i <= 4; i++) {
                QualityControlReport qualityControlReport = new QualityControlReport();
                qualityControlReport.setTime((i - 1) * 6 + "-" + i * 6);
                if (CollectionUtils.isNotEmpty(list1)) {
                    //设置自身温度平均值
                    qualityControlReport.setSelfTemperatureAvg(list1.get(i - 1).getMeanValue());
                    //设置自身二氧化碳浓度
                    qualityControlReport.setSelfCarbonDioxideConcentration(list1.get(i - 1).getCdMv());
                    //设置自身湿度平均值
                    qualityControlReport.setSelfHumidityAvg(list1.get(i - 1).getHumidityMv());
                    //设置自身氧气浓度
                    qualityControlReport.setSelfOxygenConcentration(list1.get(i - 1).getOxygenMv());
                    //设置第三方MT100温度平均值
                    qualityControlReport.setTemperatureAvgMT100(list1.get(i - 1).getThirdTemperatureMvMT100());
                    //设置第三方MT300温度平均值
                    qualityControlReport.setTemperatureAvgMT300(list1.get(i - 1).getThirdTemperatureMvMT300());
                    //设置第三方MT300二氧化碳浓度
                    qualityControlReport.setCarbonDioxideConcentrationMT300(list1.get(i - 1).getThirdCdMv());
                    //设置第三方氧气浓度平均值
                    qualityControlReport.setThirdYqMv(list1.get(i - 1).getThirdYqMv());
                }
                list.add(qualityControlReport);
            }
            //获取培养箱在某天的所有数据
            if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
                Map<Integer, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels.stream()
                        .collect(Collectors.groupingBy(QcEquipmentRecordModel::getEqId));
                List<QcEquipmentRecordModel> modelList = collect.get(qcEquipment.getId());
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        Date createTime = qcr.getCreateTime();
                        EquipmentRecordServiceImplUtil.determineSetPropertiesForPYX(qcr, createTime, list);
                    });
                }
            }
            qualityControlReportList.setQcrs(list);
            equipmentRecordServiceImplUtilService.setRecordInPYX(qualityControlReportList.getEqId(), date, qualityControlReportList, finalQcMonitorsMap, null, "day", finalAllSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        });
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }

    /**
     * 获取冰箱每日质控报表数据
     *
     * @param date   时间
     * @param userId 用户id
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryDayForBX(String date, String userId) {
        //查看外网数据是否拉取成功,未拉取成功拉取一次
        Map<String, List<AvgTempModel>> map = iRefrigeratormvService.selectTemp(date);
        if (null == map) {
            map = iRefrigeratormvService.selectTemp(FIXEDTIME);
        }
        //查询所有设备类型相等的设备集合
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .eq(QcEquipment::getEnable, "0")
                .eq(QcEquipment::getClassifyId, "1"));
        //获取类型相等的设备id集合
        List<Integer> collect1 = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        Map<Integer, String> eqNameMap = equipmentRecordServiceImplUtilService.getEqNameMap(collect1);
        //获取所有冰箱指定时间的维护记录集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForDay(date, "1");
        Map<Integer, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //将qcMonitors转化成以冰箱id为键，所有冰箱id等于键的QcMonitor对象的集合的map结构
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(QcMonitor::getEqId));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        //获取指定时间内所有冰箱的温度数据集合，键是冰箱的名称，值是该冰箱每个时间段的温度对象集合
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> QcEquipmentRecordModels = qcEquipmentRecordMapper.getQualityControlReportForEveryDay(date, "1");
        //遍历所有的设备id
        for (int n = 0; n < collect1.size(); n++) {
            Integer integer = collect1.get(n);
            List<QualityControlReport> list = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(integer);
            String deviceName = eqNameMap.get(integer);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(date);
            //获取温度数据集合
            //获取对应冰箱的指定日期的温度数据集合
            List<AvgTempModel> avgTempModels = map.get(String.valueOf(integer));
            for (int i = 1; i <= 8; i++) {
                QualityControlReport qualityControlReport = new QualityControlReport();
                qualityControlReport.setTime((i - 1) * 3 + "-" + i * 3);
                if (CollectionUtils.isNotEmpty(avgTempModels)) {
                    //设置温度平均值属性的值
                    for (int k = 0; k < avgTempModels.size(); k++) {
                        Double mean_value = avgTempModels.get(k).getMean_value();
                        String timeInterval = avgTempModels.get(k).getTimeInterval();
                        if (StringUtils.equals(timeInterval, i + "")) {
                            qualityControlReport.setSelfTemperatureAvg(mean_value);
                        }
                    }
                }
                list.add(qualityControlReport);
            }
            //获取所有冰箱某天的数据
            if (CollectionUtils.isNotEmpty(QcEquipmentRecordModels)) {
                //根据设备id进行分组
                Map<Integer, List<QcEquipmentRecordModel>> collect = QcEquipmentRecordModels.stream()
                        .collect(Collectors.groupingBy(QcEquipmentRecordModel::getEqId));
                //获取对应id的数据集合
                List<QcEquipmentRecordModel> modelList = collect.get(integer);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    //遍历某个冰箱的所有数据
                    modelList.forEach(qcr -> {
                        Date createTime = qcr.getCreateTime();
                        //根据上下班状态设置属性
                        EquipmentRecordServiceImplUtil.determineSetPropertiesForBX(qcr, createTime, list);
                    });
                }
            }
            //将对应的QualityControlReport对象的数据集合放进qualityControlReportList对象的qcrs属性中
            qualityControlReportList.setQcrs(list);
            //获取对应设备指定时间的维护记录
            //设置维护记录的值并添加到qualityControlReportList对象的属性中
            equipmentRecordServiceImplUtilService.setRecord(qualityControlReportList.getEqId(), date, qualityControlReportList, qcMonitorsMap, null, "day", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }


    /**
     * 获取环境指定时间区间内的质控报表数据
     *
     * @param eqId
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryMonthForHJ(int eqId, String startTime, String endTime) {
        //获取指定开始时间到结束时间没一天对应的日期字符串集合
        List<String> timeList = EquipmentRecordServiceImplUtil.timeDifferenceCount(startTime, endTime);
        String deviceName = qcEquipmentMapper.selectById(eqId).getDeviceName();
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForMonth(eqId, startTime, endTime);
        Map<String, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd").format(q.getCreateTime())));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        //获取检测月数据集合
        Map<String, List<Environmentmv>> environmentmvMonth = iEnvironmentmvService.selectEnvironmentmvmonth(String.valueOf(eqId), startTime, endTime);
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
        for (int n = 0; n < timeList.size(); n++) {
            String timeStr = timeList.get(n);
            List<QualityControlReport> list2 = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(timeStr);
            for (int i = 1; i <= 4; i++) {
                QualityControlReport qualityControlReport = new QualityControlReport();
                qualityControlReport.setTime((i - 1) * 6 + "-" + i * 6);
                list2.add(qualityControlReport);
            }
            //如果获取的检测记录数据有数据就将其数据的值set到qualityControlReport对象对应的属性中，得先pan'du
            if (environmentmvMonth != null) {
                List<Environmentmv> environmentmvs = environmentmvMonth.get(timeStr);
                if (CollectionUtils.isNotEmpty(environmentmvs)) {
                    environmentmvs.forEach(env -> {
                        String timeInterval = env.getTimeInterval();
                        if (StringUtils.equals("1", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list2, env, 0);
                        } else if (StringUtils.equals("2", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list2, env, 1);
                        } else if (StringUtils.equals("3", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list2, env, 2);
                        } else if (StringUtils.equals("4", timeInterval)) {
                            EquipmentRecordServiceImplUtil.setEnvProperties(list2, env, 3);
                        }
                    });
                }
            }
            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, List<QcEquipmentRecordModel>> map = list.stream()
                        .collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd")
                                .format(q.getCreateTime())));
                List<QcEquipmentRecordModel> modelList = map.get(timeStr);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        Date createTime = qcr.getCreateTime();
                        EquipmentRecordServiceImplUtil.determineSetPropertiesForHJ(qcr, createTime, list2);
                    });
                }
            }
            qualityControlReportList.setQcrs(list2);
            equipmentRecordServiceImplUtilService.setRecordForHJ(qualityControlReportList.getEqId(), timeStr, qualityControlReportList, null, qcMonitorsMap, "month", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }

    /**
     * 获取胚胎库指定时间区间内的质控报表数据
     *
     * @param eqId
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryMonthForPTK(int eqId, String startTime, String endTime) {
        //获取指定开始时间到结束时间没一天对应的日期字符串集合
        List<String> timeList = EquipmentRecordServiceImplUtil.timeDifferenceCount(startTime, endTime);
        String deviceName = qcEquipmentMapper.selectById(eqId).getDeviceName();
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForMonth(eqId, startTime, endTime);
        Map<String, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd").format(q.getCreateTime())));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
        for (int n = 0; n < timeList.size(); n++) {
            String timeStr = timeList.get(n);
            List<QualityControlReport> list2 = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(timeStr);
            QualityControlReport qualityControlReport = new QualityControlReport();
            list2.add(qualityControlReport);
            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, List<QcEquipmentRecordModel>> map = list.stream()
                        .collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd")
                                .format(q.getCreateTime())));
                List<QcEquipmentRecordModel> modelList = map.get(timeStr);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        String workStatus = qcr.getWorkStatus();
                        if (StringUtils.isNotEmpty(workStatus)) {
                            //表示上班巡检
                            if (StringUtils.equals("1", workStatus)) {
                                list2.get(0).setIdOnWork(String.valueOf(qcr.getId()));
                                list2.get(0).setInspectionTimeOnWork(qcr.getCreateTime());
                                list2.get(0).setCheckingPeopleOnWork(qcr.getCreateBy());
                                list2.get(0).setMonitoringSystemOnWork(qcr.getMonitoringSystem());
                                list2.get(0).setCanisterLockOnWork(qcr.getCanisterLock());
                                list2.get(0).setCanisterTemperatureOnWork(qcr.getCanisterTemperature());
                                list2.get(0).setTankTemperatureInfoOnWork(qcr.getTankTemperatureInfo());
                                list2.get(0).setTankLockInfoOnWork(qcr.getTankLockInfo());
                                //表示下班巡检
                            } else if (StringUtils.equals("2", workStatus)) {
                                list2.get(0).setIdOffWork(qcr.getId());
                                list2.get(0).setInspectionTimeOffWork(qcr.getCreateTime());
                                list2.get(0).setCheckingPeopleOffWork(qcr.getCreateBy());
                                list2.get(0).setMonitoringSystemOffWork(qcr.getMonitoringSystem());
                                list2.get(0).setCanisterLockOffWork(qcr.getCanisterLock());
                                list2.get(0).setCanisterTemperatureOffWork(qcr.getCanisterTemperature());
                                list2.get(0).setTankTemperatureInfoOffWork(qcr.getTankTemperatureInfo());
                                list2.get(0).setTankLockInfoOffWork(qcr.getTankLockInfo());
                            }
                        }
                    });
                }
            }
            qualityControlReportList.setQcrs(list2);
            //设置维护记录属性值和是否添加液氮的属性值
            equipmentRecordServiceImplUtilService.setRecord(qualityControlReportList.getEqId(), timeStr, qualityControlReportList, null, qcMonitorsMap, "month", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }

    /**
     * 获取离心机或工作站指定时间区间内的质控报表数据
     *
     * @param eqId
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryMonthForLXJOrGZZ(int eqId, String startTime, String endTime) {
        //获取指定开始时间到结束时间没一天对应的日期字符串集合
        List<String> timeList = EquipmentRecordServiceImplUtil.timeDifferenceCount(startTime, endTime);
        String deviceName = qcEquipmentMapper.selectById(eqId).getDeviceName();
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForMonth(eqId, startTime, endTime);
        Map<String, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd").format(q.getCreateTime())));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
        for (int n = 0; n < timeList.size(); n++) {
            String timeStr = timeList.get(n);
            List<QualityControlReport> list2 = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(timeStr);
            QualityControlReport qualityControlReport = new QualityControlReport();
            list2.add(qualityControlReport);
            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, List<QcEquipmentRecordModel>> map = list.stream()
                        .collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd")
                                .format(q.getCreateTime())));
                List<QcEquipmentRecordModel> modelList = map.get(timeStr);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        String workStatus = qcr.getWorkStatus();
                        if (StringUtils.isNotEmpty(workStatus)) {
                            //表示上班巡检
                            if (StringUtils.equals("1", workStatus)) {
                                list2.get(0).setIdOnWork(String.valueOf(qcr.getId()));
                                list2.get(0).setInspectionTimeOnWork(qcr.getCreateTime());
                                list2.get(0).setRunningStatusOnWork(qcr.getRunningStatus());
                                list2.get(0).setCheckingPeopleOnWork(qcr.getCreateBy());
                                //表示下班巡检
                            } else if (StringUtils.equals("2", workStatus)) {
                                list2.get(0).setIdOffWork(qcr.getId());
                                list2.get(0).setInspectionTimeOffWork(qcr.getCreateTime());
                                list2.get(0).setRunningStatusOffWork(qcr.getRunningStatus());
                                list2.get(0).setCheckingPeopleOffWork(qcr.getCreateBy());
                            }
                        }
                    });
                }
            }
            qualityControlReportList.setQcrs(list2);
            equipmentRecordServiceImplUtilService.setRecord(qualityControlReportList.getEqId(), timeStr, qualityControlReportList, null, qcMonitorsMap, "month", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }

    /**
     * 获取指定显微镜指定时间区间内的质控报表数据
     *
     * @param eqId
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryMonthForXWJ(int eqId, String startTime, String endTime) {
        //获取指定开始时间到结束时间没一天对应的日期字符串集合
        List<String> timeList = EquipmentRecordServiceImplUtil.timeDifferenceCount(startTime, endTime);
        String deviceName = qcEquipmentMapper.selectById(eqId).getDeviceName();
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForMonth(eqId, startTime, endTime);
        Map<String, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd").format(q.getCreateTime())));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
        for (int n = 0; n < timeList.size(); n++) {
            String timeStr = timeList.get(n);
            List<QualityControlReport> list2 = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(timeStr);
            QualityControlReport qualityControlReport = new QualityControlReport();
            list2.add(qualityControlReport);
            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, List<QcEquipmentRecordModel>> map = list.stream()
                        .collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd")
                                .format(q.getCreateTime())));
                List<QcEquipmentRecordModel> modelList = map.get(timeStr);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    modelList.forEach(qcr -> {
                        String workStatus = qcr.getWorkStatus();
                        if (StringUtils.isNotEmpty(workStatus)) {
                            //表示上班巡检
                            if (StringUtils.equals("1", workStatus)) {
                                list2.get(0).setIdOnWork(String.valueOf(qcr.getId()));
                                list2.get(0).setInspectionTimeOnWork(qcr.getCreateTime());
                                list2.get(0).setRunningStatusOnWork(qcr.getRunningStatus());
                                list2.get(0).setRemarkOnWork(qcr.getRemark());
                                list2.get(0).setCheckingPeopleOnWork(qcr.getCreateBy());
                                list2.get(0).setRemarkOnWork(qcr.getRemark());
                                //表示下班巡检
                            } else if (StringUtils.equals("2", workStatus)) {
                                list2.get(0).setIdOffWork(qcr.getId());
                                list2.get(0).setInspectionTimeOffWork(qcr.getCreateTime());
                                list2.get(0).setRunningStatusOffWork(qcr.getRunningStatus());
                                list2.get(0).setRemarkOffWork(qcr.getRemark());
                                list2.get(0).setCheckingPeopleOffWork(qcr.getCreateBy());
                                list2.get(0).setRemarkOffWork(qcr.getRemark());
                            }
                        }
                    });
                }
            }
            qualityControlReportList.setQcrs(list2);
            equipmentRecordServiceImplUtilService.setRecordInXWJ(qualityControlReportList.getEqId(), timeStr, qualityControlReportList, null, qcMonitorsMap, "month", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }

    /**
     * 获取指定培养箱指定时间区间内的质控报表数据
     *
     * @param eqId      设备id
     * @param startTime 开始时间 yyyy-MM-dd
     * @param endTime   结束时间 yyyy-MM-dd
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryMonthForPYX(int eqId, String startTime, String endTime) {
        //获取指定开始时间到结束时间没一天对应的日期字符串集合
        List<String> timeList = EquipmentRecordServiceImplUtil.timeDifferenceCount(startTime, endTime);
        QcEquipment qcEquipment = qcEquipmentMapper.selectById(eqId);
        String deviceName = qcEquipment.getDeviceName();
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForMonth(eqId, startTime, endTime);
        Map<String, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //将qcMonitors集合按时间分组
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd").format(q.getCreateTime())));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        //获取检测数据集合
        Map<String, List<IncubModel>> incubModelMaps = iIncubatormvService.selectIncubmonth(String.valueOf(eqId), startTime, endTime);
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
        for (int n = 0; n < timeList.size(); n++) {
            String timeStr = timeList.get(n);
            List<QualityControlReport> list2 = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            qualityControlReportList.setDeviceName(deviceName);
            qualityControlReportList.setDate(timeStr);
            if (incubModelMaps != null) {
                //通过日期获取对应键对应的检测数据集合
                List<IncubModel> list1 = incubModelMaps.get(timeStr);
                for (int i = 1; i <= 4; i++) {
                    QualityControlReport qualityControlReport = new QualityControlReport();
                    qualityControlReport.setTime((i - 1) * 6 + "-" + i * 6);
                    if (CollectionUtils.isNotEmpty(list1)) {
                        //设置自身温度平均值
                        qualityControlReport.setSelfTemperatureAvg(list1.get(i - 1).getMeanValue());
                        //设置自身二氧化碳浓度
                        qualityControlReport.setSelfCarbonDioxideConcentration(list1.get(i - 1).getCdMv());
                        //设置自身湿度平均值
                        qualityControlReport.setSelfHumidityAvg(list1.get(i - 1).getHumidityMv());
                        //设置自身氧气浓度
                        qualityControlReport.setSelfOxygenConcentration(list1.get(i - 1).getOxygenMv());
                        //设置第三方MT100温度平均值
                        qualityControlReport.setTemperatureAvgMT100(list1.get(i - 1).getThirdTemperatureMvMT100());
                        //设置第三方MT300温度平均值
                        qualityControlReport.setTemperatureAvgMT300(list1.get(i - 1).getThirdTemperatureMvMT300());
                        //设置第三方MT300二氧化碳浓度
                        qualityControlReport.setCarbonDioxideConcentrationMT300(list1.get(i - 1).getThirdCdMv());
                        //设置第三方氧气浓度平均值
                        qualityControlReport.setThirdYqMv(list1.get(i - 1).getThirdYqMv());
                    }
                    list2.add(qualityControlReport);
                }
            } else {
                for (int i = 1; i <= 4; i++) {
                    QualityControlReport qualityControlReport = new QualityControlReport();
                    qualityControlReport.setTime((i - 1) * 6 + "-" + i * 6);
                    list2.add(qualityControlReport);
                }
            }
            //获取指定培养箱在指定时间区间内的所有数据集合
            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, List<QcEquipmentRecordModel>> map = list.stream()
                        .collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd")
                                .format(q.getCreateTime())));
                List<QcEquipmentRecordModel> modelList = map.get(timeStr);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    //遍历某个培养箱的所有数据
                    modelList.forEach(qcr -> {
                        Date createTime = qcr.getCreateTime();
                        //根据上下班状态设置属性
                        EquipmentRecordServiceImplUtil.determineSetPropertiesForPYX(qcr, createTime, list2);
                    });
                }
            }
            qualityControlReportList.setQcrs(list2);
            equipmentRecordServiceImplUtilService.setRecordInPYX(qualityControlReportList.getEqId(), timeStr, qualityControlReportList, null, qcMonitorsMap, "month", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }

    /**
     * 获取冰箱指定时间区间内的质控报表数据
     *
     * @param eqId      设备id
     * @param startTime 开始时间 yyyy-MM-dd
     * @param endTime   结束时间 yyyy-MM-dd
     * @return
     */
    @Override
    public List<QualityControlReportList> getQualityControlReportEveryMonthForBX(int eqId, String startTime, String endTime) {
        //获取指定开始时间到结束时间没一天对应的日期字符串集合
        List<String> list1 = EquipmentRecordServiceImplUtil.timeDifferenceCount(startTime, endTime);
        QcEquipment qcEquipment = qcEquipmentMapper.selectById(eqId);
        //获取某个冰箱一个月的温度数据集合，键是冰箱数据的日期
        Map<String, List<AvgTempModel>> mapAll = iRefrigeratormvService.selectTempmonth(String.valueOf(eqId), startTime, endTime);
        //获取某个冰箱指定时间区间内的所有维护记录数据集合
        List<QcMonitor> qcMonitors = qcMonitorMapper.getMaintenanceRecordForRefrigeratorForMonth(eqId, startTime, endTime);
        Map<String, List<QcMonitor>> qcMonitorsMap = null;
        Set<String> createBys = null;
        Map<String, String> allSysUserinfoByIds = null;
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //将qcMonitors集合按时间分组
            qcMonitorsMap = qcMonitors.stream().collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd").format(q.getCreateTime())));
            createBys = qcMonitors.stream().map(QcMonitor::getCreateBy).collect(Collectors.toSet());
            //获取维护记录操作人id对应操作人姓名的map集合
            allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(createBys);
        }
        List<QualityControlReportList> collecter = new ArrayList<>();
        List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
        for (int n = 0; n < list1.size(); n++) {
            String timeStr = list1.get(n);
            List<QualityControlReport> list2 = new ArrayList<>();
            QualityControlReportList qualityControlReportList = new QualityControlReportList();
            qualityControlReportList.setEqId(eqId);
            qualityControlReportList.setDeviceName(qcEquipment.getDeviceName());
            qualityControlReportList.setDate(timeStr);
            //获取对应冰箱的指定日期的温度数据集合
            List<AvgTempModel> avgTempModels = mapAll.get(timeStr);
            for (int i = 1; i <= 8; i++) {
                QualityControlReport qualityControlReport = new QualityControlReport();
                qualityControlReport.setTime((i - 1) * 3 + "-" + i * 3);
                if (CollectionUtils.isNotEmpty(avgTempModels)) {
                    //设置温度平均值属性
                    qualityControlReport.setSelfTemperatureAvg(avgTempModels.get(i - 1).getMean_value());
                }
                list2.add(qualityControlReport);
            }
            if (CollectionUtils.isNotEmpty(list)) {
                //将获取的数据按时间日期分组
                Map<String, List<QcEquipmentRecordModel>> map = list.stream()
                        .collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd")
                                .format(q.getCreateTime())));
                //获取该冰箱每天的数据集合
                List<QcEquipmentRecordModel> modelList = map.get(timeStr);
                if (CollectionUtils.isNotEmpty(modelList)) {
                    //遍历某个冰箱的所有数据
                    modelList.forEach(qcr -> {
                        Date createTime = qcr.getCreateTime();
                        //根据上下班状态设置属性
                        EquipmentRecordServiceImplUtil.determineSetPropertiesForBX(qcr, createTime, list2);
                    });
                }
            }
            //将对应的QualityControlReport对象的数据集合放进qualityControlReportList对象的qcrs属性中
            qualityControlReportList.setQcrs(list2);
            //获取对应设备指定时间的维护记录
            equipmentRecordServiceImplUtilService.setRecord(qualityControlReportList.getEqId(), timeStr, qualityControlReportList, null, qcMonitorsMap, "month", allSysUserinfoByIds);
            collecter.add(qualityControlReportList);
        }
        //设置数字签名属性
        equipmentRecordServiceImplUtilService.setDigitalSignatureAttribute(collecter);
        //设置姓名
        equipmentRecordServiceImplUtilService.setQualityControlReportUserName(collecter);
        return collecter;
    }


    /**
     * 生成指定设置指定时间内的签章记录
     *
     * @param startTime
     * @param endTime
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addDigitalSignature(String startTime, String endTime) {
        LocalDateTime localDateTime = DateUtil.changeStrToDateTime(startTime);
        List<String> classifyIds = new ArrayList<>();
        classifyIds.add("1");
        classifyIds.add("2");
        classifyIds.add("4");
        classifyIds.add("5");
        classifyIds.add("6");
        classifyIds.add("7");
        classifyIds.add("9");
        classifyIds.add("11");
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectList(Wrappers.lambdaQuery(new QcEquipment())
                .in(QcEquipment::getClassifyId, classifyIds));
        List<Integer> ids = qcEquipments.stream().map(QcEquipment::getId).collect(Collectors.toList());
        //获取开始时间和结束时间之间相隔了多少天，因为计算的是相隔多少天，所以在当天的巡检记录也需要生成签章，所以获取的时间加一天
        Long aLong = countDate(startTime, endTime) + 1;
        for (int j = 0; j < ids.size(); j++) {
            int eqId = ids.get(j);
            //如果设备是工作台
            if (237 == eqId || 238 == eqId || 239 == eqId || 240 == eqId || 241 == eqId || 242 == eqId || 243 == eqId) {
                qcEquipmentRecordService.addDigitalSignatureForGZT(eqId, startTime, endTime);
            } else {
                //查询对应设备在指定日期区间内的所有巡检记录
                List<QcEquipmentRecordModel> list = qcEquipmentRecordMapper.getQualityControlReportForEveryMonth(eqId, startTime, endTime);
                if (CollectionUtils.isNotEmpty(list)) {
                    Map<String, List<QcEquipmentRecordModel>> map = list.stream()
                            .collect(Collectors.groupingBy(q -> new SimpleDateFormat("yyyy-MM-dd")
                                    .format(q.getCreateTime())));
                    List<QualityControlReportList> collect = new ArrayList<>();
                    for (int n = 0; n < aLong; n++) {
                        //获取当前下标的时间,用开始时间加上当前n的值
                        LocalDateTime localDateTimeIndex = localDateTime.plusDays(n);
                        LocalDate localDate = localDateTimeIndex.toLocalDate();
                        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                        String time = localDate.format(fmt);
                        QualityControlReportList qualityControlReportList = new QualityControlReportList();
                        qualityControlReportList.setEqId(eqId);
                        qualityControlReportList.setDate(time);
                        List<QualityControlReport> list1 = new ArrayList<>();
                        //获取当前时间内的巡检记录集合
                        List<QcEquipmentRecordModel> modelList = map.get(time);
                        if (CollectionUtils.isNotEmpty(modelList)) {
                            QualityControlReport qualityControlReport = new QualityControlReport();
                            modelList.forEach(qcr -> {
                                String workStatus = qcr.getWorkStatus();
                                if (StringUtils.equals("1", workStatus)) {
                                    qualityControlReport.setIdOnWork(String.valueOf(qcr.getId()));
                                } else if (StringUtils.equals("2", workStatus)) {
                                    qualityControlReport.setIdOffWork(qcr.getId());
                                }
                            });
                            list1.add(qualityControlReport);
                            qualityControlReportList.setQcrs(list1);
                        } else {
                            continue;
                        }
                        //过滤掉上班巡检记录为null的数据
                        List<QualityControlReport> qcrs = qualityControlReportList.getQcrs();
                        if (CollectionUtils.isNotEmpty(qcrs)) {
                            QualityControlReport qualityControlReport = qcrs.get(0);
                            String idOnWork = qualityControlReport.getIdOnWork();
                            //如果当前合并的上下班巡检记录中上班巡检记录id不为null，则保留，为null则筛选出去
                            if (StringUtils.isNotEmpty(idOnWork)) {
                                collect.add(qualityControlReportList);
                            }
                        }
                    }
                    //如果只保留上班巡检记录存在的集合不为null
                    if (CollectionUtils.isNotEmpty(collect)) {
                        List<DigitalSignature> digitalSignatures = new ArrayList<>();
                        for (QualityControlReportList c : collect) {
                            //创建签章对象，并设置相关属性，最后批量添加签章记录数据
                            DigitalSignature digitalSignature = new DigitalSignature();
                            digitalSignature.setEqId(c.getEqId() + "");
                            String date = c.getDate();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                            try {
                                Date parse = simpleDateFormat.parse(date);
                                digitalSignature.setSignatureTime(parse);
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            digitalSignature.setIsSignature("1");
                            digitalSignature.setWorkOnRecordId(c.getQcrs().get(0).getIdOnWork().toString());
                            Long idOffWork = c.getQcrs().get(0).getIdOffWork();
                            if (null != idOffWork) {
                                digitalSignature.setWorkOffRecordId(idOffWork.toString());
                            }
                            digitalSignature.setChecker("李城");
                            digitalSignatures.add(digitalSignature);
                        }
                        qcDigitalSignatureService.saveBatch(digitalSignatures);
                    }
                }
            }
        }
    }

    /**
     * 生成工作台指定设备指定时间内的签章记录
     *
     * @param eqId
     * @param startTime
     * @param endTime
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addDigitalSignatureForGZT(int eqId, String startTime, String endTime) {
        List<WorkbenchModel> list = this.getWorkbenchModelEveryMonthForGZT(eqId, startTime, endTime);
        if (CollectionUtils.isNotEmpty(list)) {
            //删选掉操作前巡检记录id为null的数据
            List<WorkbenchModel> collect = list.stream().filter(a -> null != a.getIdBegin()).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(collect)) {
                List<DigitalSignature> digitalSignatures = new ArrayList<>();
                collect.forEach(c -> {
                    DigitalSignature digitalSignature = new DigitalSignature();
                    digitalSignature.setEqId(c.getEqId().toString());
                    String day = c.getDay();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        Date date = simpleDateFormat.parse(day);
                        digitalSignature.setSignatureTime(date);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    digitalSignature.setIsSignature("1");
                    digitalSignature.setWorkOnRecordId(c.getIdBegin().toString());
                    Long idEnd = c.getIdEnd();
                    if (null != idEnd) {
                        digitalSignature.setWorkOffRecordId(idEnd.toString());
                    }
                    digitalSignature.setChecker("李城");
                    digitalSignatures.add(digitalSignature);
                });
                qcDigitalSignatureService.saveBatch(digitalSignatures);
            }
        }
    }


}
